home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 332_01 / overlay.c < prev    next >
C/C++ Source or Header  |  1990-01-05  |  5KB  |  156 lines

  1. /****************************************************************/
  2. /* Overlay() and overwrite() functions of the PCcurses package    */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*                Bjorn Larsson (bl@infovox.se)    */
  10. /****************************************************************/
  11. /* 1.4:  Overlaying window will not line up with over-        */
  12. /*     layed window's origin, but at it's 'own' origin    */
  13. /*     relative to the overlayed's origin. Use of short    */
  14. /*     wherever possible. Portability improvements:    900114    */
  15. /* 1.3:     MSC -W3, Turbo'C' -w -w-pro checks:        881005    */
  16. /* 1.2:     Max limits off by 1. Fixed thanks to S. Creps:    881002    */
  17. /* 1.0:     Release:                    870515    */
  18. /****************************************************************/
  19.  
  20. #include <curses.h>
  21. #include <curspriv.h>
  22.  
  23. char _curses_overlay_rcsid[] = "@(#)overlay.c    v.1.4  - 900114";
  24.  
  25. /****************************************************************/
  26. /* Overlay() overwrites 'win1' upon 'win2', with 'win1' appea-    */
  27. /* ring in 'win2' at it own origin relative to 'win2's origin.    */
  28. /* This is a departure, but a desirable one, from the initial    */
  29. /* definition of this function. Overlay is transparent; blanks    */
  30. /* from 'win1' are not copied to 'win2'.            */
  31. /****************************************************************/
  32.  
  33. void overlay(win1, win2)
  34.   WINDOW    *win1, *win2;
  35.   {
  36.   short        *minchng;
  37.   short        *maxchng;
  38.   short        *w1ptr;
  39.   short        *w2ptr;
  40.   short         attrs;
  41.   short         col;
  42.   short         line;
  43.   short         last_line;
  44.   short         last_col;
  45.  
  46.   last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  47.   last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  48.   attrs = win2->_attrs & ATR_MSK;
  49.   minchng = win2->_minchng + win1->_begy;
  50.   maxchng = win2->_maxchng + win1->_begy;
  51.  
  52.   for(line = win1->_begy;  line <= last_line;  line++)
  53.     {
  54.     register short   fc, lc;
  55.  
  56.     w1ptr = win1->_line[line - win1->_begy];
  57.     w2ptr = win2->_line[line] + win1->_begx;
  58.     fc = _NO_CHANGE;
  59.  
  60.     for(col = win1->_begx;  col <= last_col;  col++)
  61.       {
  62.       if ((*w1ptr & CHR_MSK) != ' ')
  63.     {
  64.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  65.     if (fc == _NO_CHANGE)
  66.       fc = col;
  67.     lc = col;
  68.     } /* if */
  69.       w1ptr++;
  70.       w2ptr++;
  71.       } /* for */
  72.  
  73.     if (*minchng == _NO_CHANGE)
  74.       {
  75.       *minchng = fc;
  76.       *maxchng = lc;
  77.       } /* if */
  78.     else
  79.       if (fc != _NO_CHANGE)
  80.     {
  81.     if (fc < *minchng)
  82.       *minchng = fc;
  83.     if (lc > *maxchng)
  84.       *maxchng = lc;
  85.     } /* else if */
  86.     minchng++;
  87.     maxchng++;
  88.     } /* for */
  89.   } /* overlay */
  90.  
  91. /****************************************************************/
  92. /* Overwrite() overwrites 'win1' upon 'win2', with 'win1' ap-    */
  93. /* pearing in 'win2' at it own origin relative to 'win2's ori-    */
  94. /* gin. This is a departure, but a desirable one, from the    */
  95. /* initial definition of this function. Overwrite is non-trans-    */
  96. /* parent; blanks from 'win1' are copied to 'win2'.        */
  97. /****************************************************************/
  98.  
  99. void    overwrite(win1, win2)
  100.   WINDOW    *win1, *win2;
  101.   {
  102.   short        *minchng;
  103.   short        *maxchng;
  104.   short        *w1ptr;
  105.   short        *w2ptr;
  106.   short         attrs;
  107.   short         col;
  108.   short         line;
  109.   short         last_line;
  110.   short         last_col;
  111.  
  112.   last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  113.   last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  114.   attrs = win2->_attrs & ATR_MSK;
  115.   minchng = win2->_minchng + win1->_begy;
  116.   maxchng = win2->_maxchng + win1->_begy;
  117.  
  118.   for(line = win1->_begy;  line <= last_line;  line++)
  119.     {
  120.     register short   fc, lc;
  121.  
  122.     w1ptr = win1->_line[line - win1->_begy];
  123.     w2ptr = win2->_line[line] + win1->_begx;
  124.     fc = _NO_CHANGE;
  125.  
  126.     for(col = win1->_begx;  col <= last_col;  col++)
  127.       {
  128.       if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK))
  129.     {
  130.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  131.     if (fc == _NO_CHANGE)
  132.       fc = col;
  133.     lc = col;
  134.     } /* if */
  135.       w1ptr++;
  136.       w2ptr++;
  137.       } /* for */
  138.  
  139.     if (*minchng == _NO_CHANGE)
  140.       {
  141.       *minchng = fc;
  142.       *maxchng = lc;
  143.       } /* if */
  144.     else
  145.       if (fc != _NO_CHANGE)
  146.     {
  147.     if (fc < *minchng)
  148.       *minchng = fc;
  149.     if (lc > *maxchng)
  150.       *maxchng = lc;
  151.     } /* else if */
  152.     minchng++;
  153.     maxchng++;
  154.     } /* for */
  155.   } /* overwrite */
  156.